﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RepositoryEntity.Extension
{
   public static class ControllerBaseExtension
    {
        public static UserInfo GetSessionUserInfo(this ControllerBase controllerBase)
        {
            var userInfoJson = controllerBase.HttpContext.Session.GetString("UserInfo");
            if (string .IsNullOrEmpty(userInfoJson))
            {
                return null;
            }
            UserInfo userInfo = JsonConvert.DeserializeObject<UserInfo>(userInfoJson);
            return userInfo;
        }
    }
}
